package com.ruoyi.project.system.punishment.controller;

import java.util.List;

import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.punishment.domain.Punishment;
import com.ruoyi.project.system.punishment.service.IPunishmentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 惩罚管理Controller
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@Controller
@RequestMapping("/system/punishment")
@DataSource(value = DataSourceType.SLAVE )
public class PunishmentController extends BaseController
{
    private String prefix = "system/punishment";

    @Autowired
    private IPunishmentService punishmentService;

    @RequiresPermissions("system:punishment:view")
    @GetMapping()
    public String punishment()
    {
        return prefix + "/punishment";
    }

    /**
     * 查询惩罚管理列表
     */
    @RequiresPermissions("system:punishment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Punishment punishment)
    {
        startPage();
        List<Punishment> list = punishmentService.selectPunishmentList(punishment);
        return getDataTable(list);
    }

    /**
     * 导出惩罚管理列表
     */
    @RequiresPermissions("system:punishment:export")
    @Log(title = "惩罚管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Punishment punishment)
    {
        List<Punishment> list = punishmentService.selectPunishmentList(punishment);
        ExcelUtil<Punishment> util = new ExcelUtil<Punishment>(Punishment.class);
        return util.exportExcel(list, "惩罚管理数据");
    }

    /**
     * 新增惩罚管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存惩罚管理
     */
    @RequiresPermissions("system:punishment:add")
    @Log(title = "惩罚管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Punishment punishment)
    {
        return toAjax(punishmentService.insertPunishment(punishment));
    }

    /**
     * 修改惩罚管理
     */
    @RequiresPermissions("system:punishment:edit")
    @GetMapping("/edit/{iid}")
    public String edit(@PathVariable("iid") Long iid, ModelMap mmap)
    {
        Punishment punishment = punishmentService.selectPunishmentByIid(iid);
        mmap.put("punishment", punishment);
        return prefix + "/edit";
    }

    /**
     * 修改保存惩罚管理
     */
    @RequiresPermissions("system:punishment:edit")
    @Log(title = "惩罚管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Punishment punishment)
    {
        return toAjax(punishmentService.updatePunishment(punishment));
    }

    /**
     * 删除惩罚管理
     */
    @RequiresPermissions("system:punishment:remove")
    @Log(title = "惩罚管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(punishmentService.deletePunishmentByIids(ids));
    }
}
